package Presentacion;


import AccesoDatos.Comando;
import AccesoDatos.Conexion;
import LogicaNegocio.Empleado;
import Presentacion.frmAdminEmpleado;
import java.awt.Dimension;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author REYES
 */
public class frmAgregarEmpleado extends javax.swing.JInternalFrame {
        Conexion conexion;
        Empleado empleado;
        int modo;
        String CedulaActual; // Variable para guardar la cedula en caso de querer modificarla
        
    public frmAgregarEmpleado(Conexion Pconexion, int Pmodo, Empleado Pempleado) {
        conexion = Pconexion;
        empleado = Pempleado;
        modo = Pmodo;  // 1 es para modificar y 0 para agregar uno nuevo
        initComponents();
        // Si el modo es igual a 1, se llenan los campos de texto con la info del empleado seleccionado
        if(modo == 1){
        CedulaActual = Integer.toString(empleado.getId_Empleado()); // Aqui guardamos la cedula actual
        txtCedula.setText(Integer.toString(empleado.getId_Empleado()));
        txtNombre.setText(empleado.getNombre());
        txtPrimerApellido.setText(empleado.getPrimer_Apellido());
        txtSegundoApellido.setText(empleado.getSegundo_Apellido());
        txtTelefono.setText(empleado.getTelefono());
        txtEmail.setText(empleado.getEmail());
        if(empleado.getTipo().equals("Ejecutivo de Cobro")){
            cbTipo.setSelectedIndex(0);
        }else{
               if(empleado.getTipo().equals("Ejecutivo de Servicio al Cliente")){
                    cbTipo.setSelectedIndex(1);
               }else{
                    cbTipo.setSelectedIndex(2);
               }
        }
        txtUsuario.setText(empleado.getUsuario().getUsername());
        txtPassword.setText(empleado.getUsuario().getPassword());
        btnEliminar.setVisible(true);
        btnCambiarPassword.setVisible(true);
        btnGuardar.setText("Modificar");
        }else{
        btnCambiarPassword.setVisible(false);
        btnEliminar.setVisible(false);
        }
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txtEmail = new javax.swing.JTextField();
        txtUsuario = new javax.swing.JTextField();
        txtNombre = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        txtCedula = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cbTipo = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JTextField();
        btnCambiarPassword = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtSegundoApellido = new javax.swing.JTextField();
        txtPrimerApellido = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();

        setIconifiable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos del empleado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        txtEmail.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtEmail.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        txtUsuario.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtUsuario.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        txtNombre.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtNombre.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        txtTelefono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtTelefono.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        txtCedula.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtCedula.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Usuario");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Contraseña");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("E-mail");

        cbTipo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ejecutivo de Cobro", "Ejecutivo de Servicio al Cliente", "Administrador del Sistema" }));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Teléfono");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Nombre");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Cédula");

        txtPassword.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtPassword.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        btnCambiarPassword.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnCambiarPassword.setText("Cambiar");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("1er Apellido");

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("2ndo Apellido");

        txtSegundoApellido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtSegundoApellido.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        txtPrimerApellido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtPrimerApellido.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("Tipo");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel8))
                        .addGap(22, 22, 22)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPrimerApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel10)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtSegundoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCambiarPassword)))))
                .addGap(0, 20, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtPrimerApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtSegundoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnCambiarPassword)))
                .addContainerGap())
        );

        btnGuardar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/src/imagenes/btn_guardar.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/src/imagenes/btn_cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnEliminar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/src/imagenes/eliminar.png"))); // NOI18N
        btnEliminar.setText("Eliminar");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar)))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                    .addComponent(btnEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(20, 20, 20))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // Modo 0: Agregar Empleado nuevo  Modo 1: Modificar Empleado
        if(modo == 0){
            //Aqui hay que validar que ninguno de los campos de textos esten en blanco
            try{
            
                Comando comando = new Comando();
                Comando comando2 = new Comando();
                comando.setConsulta("INSERT INTO `sicgsadb`.`tb_empleado` (`Id_Empleado`, `Nombre`, `Primer_Apellido`, `Segundo_Apellido`, `Telefono`, `Email`, `Tipo`) VALUES ('"+ txtCedula.getText() +"', '"+ txtNombre.getText() +"', '"+ txtPrimerApellido.getText() +"', '"+ txtSegundoApellido.getText() +"', '"+ txtTelefono.getText() +"', '"+ txtEmail.getText() +"', '"+ cbTipo.getSelectedItem().toString() +"')");
                comando2.setConsulta("INSERT INTO `sicgsadb`.`tb_usuario` (`Id_Empleado`, `Username`, `Password`, `Tipo`) VALUES ('"+ txtCedula.getText() +"', '"+ txtUsuario.getText() +"', '"+ txtPassword.getText() +"', '"+ cbTipo.getSelectedItem().toString() +"')");
                if(comando.updateSQL(conexion) && comando2.updateSQL(conexion)){
                    JOptionPane.showMessageDialog(this, "El empleado se ingresó exitosamente", "Información", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose(); 
                    frmAdminEmpleado fAdminEmpleado = new frmAdminEmpleado(conexion);
                    Dimension desktopSize = frmMain.jDesktopPane1.getSize();
                    Dimension jInternalFrameSize = fAdminEmpleado.getSize();
                    int width = (desktopSize.width - jInternalFrameSize.width) / 2;
                    int height = (desktopSize.height - jInternalFrameSize.height) / 2;
                    fAdminEmpleado.setLocation(width, height);
                    frmMain.jDesktopPane1.add(fAdminEmpleado);
                    fAdminEmpleado.show();
                }
                                             
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
                //System.out.println(ex.getMessage());
            }
            
        }else{// Modo 1: Modificar
                try{
                Comando comando = new Comando();
                Comando comando2 = new Comando();
                comando.setConsulta("UPDATE `sicgsadb`.`tb_empleado` SET `Id_Empleado`='"+ txtCedula.getText() +"', `Nombre`='"+ txtNombre.getText() +"', `Primer_Apellido`='"+ txtPrimerApellido.getText() +"', `Segundo_Apellido`='"+ txtSegundoApellido.getText() +"', `Telefono`='"+ txtTelefono.getText() +"', `Email`='"+ txtEmail.getText() +"', `Tipo`='"+ cbTipo.getSelectedItem().toString() +"' WHERE `Id_Empleado`='"+ this.CedulaActual +"'");
                comando2.setConsulta("UPDATE `sicgsadb`.`tb_usuario` SET `Username`='"+ txtUsuario.getText() +"', `Password`='"+ txtPassword.getText() +"', `Tipo`='"+ cbTipo.getSelectedItem().toString() +"' WHERE `Id_Empleado`='"+ txtCedula.getText() +"'");
                if(comando.updateSQL(conexion) && comando2.updateSQL(conexion)){
                    JOptionPane.showMessageDialog(this, "El empleado se modificó exitosamente", "Información", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose(); 
                    frmAdminEmpleado fAdminEmpleado = new frmAdminEmpleado(conexion);
                    Dimension desktopSize = frmMain.jDesktopPane1.getSize();
                    Dimension jInternalFrameSize = fAdminEmpleado.getSize();
                    int width = (desktopSize.width - jInternalFrameSize.width) / 2;
                    int height = (desktopSize.height - jInternalFrameSize.height) / 2;
                    fAdminEmpleado.setLocation(width, height);
                    frmMain.jDesktopPane1.add(fAdminEmpleado);
                    fAdminEmpleado.show();
                }
                                             
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
                //System.out.println(ex.getMessage());
            }        
        }
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        int i =JOptionPane.showConfirmDialog(this,"¿Realmente desea Salir?","Confirmar Salida",JOptionPane.YES_NO_OPTION);
        if(i==0){ // Si el usuario selecciona la opcion "Si", se sale del from actual y vuelve a la pantalla anterior
            this.dispose(); 
            frmAdminEmpleado fAdminEmpleado = new frmAdminEmpleado(conexion);
            Dimension desktopSize = frmMain.jDesktopPane1.getSize();
            Dimension jInternalFrameSize = fAdminEmpleado.getSize();
            int width = (desktopSize.width - jInternalFrameSize.width) / 2;
            int height = (desktopSize.height - jInternalFrameSize.height) / 2;
            fAdminEmpleado.setLocation(width, height);
            frmMain.jDesktopPane1.add(fAdminEmpleado);
            fAdminEmpleado.show();
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
         int i =JOptionPane.showConfirmDialog(this,"¿Realmente desea Eliminar el empleado?","Confirmar Salida",JOptionPane.YES_NO_OPTION);
         if(i==0){// Si el usuario selecciona la opcion "Si", se procede a eliminar el empleado de la base de datos
                try{

                    Comando comando = new Comando();
                    Comando comando2 = new Comando();

                    comando.setConsulta("DELETE FROM `sicgsadb`.`tb_usuario` WHERE `Id_Empleado`='"+ txtCedula.getText() +"'");
                    comando2.setConsulta("DELETE FROM `sicgsadb`.`tb_empleado` WHERE `Id_Empleado`='"+ txtCedula.getText() +"'");
                    if(comando.updateSQL(conexion) && comando2.updateSQL(conexion)){ // Primero hay que borrar el usuario y luego el empleado, debido a la llave foranea
                        JOptionPane.showMessageDialog(this, "El empleado se eliminó exitosamente", "Información", JOptionPane.INFORMATION_MESSAGE);
                        this.dispose(); 
                        frmAdminEmpleado fAdminEmpleado = new frmAdminEmpleado(conexion);
                        Dimension desktopSize = frmMain.jDesktopPane1.getSize();
                        Dimension jInternalFrameSize = fAdminEmpleado.getSize();
                        int width = (desktopSize.width - jInternalFrameSize.width) / 2;
                        int height = (desktopSize.height - jInternalFrameSize.height) / 2;
                        fAdminEmpleado.setLocation(width, height);
                        frmMain.jDesktopPane1.add(fAdminEmpleado);
                        fAdminEmpleado.show();
                    }

                }catch(Exception ex){
                    JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
                    //System.out.println(ex.getMessage());
                }
        }// TODO add your handling code here:
    }//GEN-LAST:event_btnEliminarActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCambiarPassword;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cbTipo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtPassword;
    private javax.swing.JTextField txtPrimerApellido;
    private javax.swing.JTextField txtSegundoApellido;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}
